/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.uduew.sjd.utils;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;

import com.uduew.sjd.api.AllLoanOrdersApi;
import com.uduew.sjd.api.GetBankInfoApi;
import com.uduew.sjd.api.ProductInfoApi;
import com.uduew.sjd.api.RepaymentMethodApi;

import java.io.File;

public class DiffUtils {

    private DiffUtil.ItemCallback<ProductInfoApi.ThoroughBean> mHomeProductItemCallback;
    private DiffUtil.ItemCallback<AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean> mLoanItemCallback;

    private DiffUtil.ItemCallback<File> mImageItemCallback;
    private DiffUtil.ItemCallback<GetBankInfoApi.HesitancyBean> mBankItemCallback;
    private DiffUtil.ItemCallback<RepaymentMethodApi.MethodsBean> mRepaymentItemCallback;

    private DiffUtils() {
    }

    private static final DiffUtils S_DIFF_UTILS = new DiffUtils();

    public static DiffUtils getInstance() {
        return S_DIFF_UTILS;
    }

    public DiffUtil.ItemCallback<ProductInfoApi.ThoroughBean> getHomeProductItemCallback() {
        if (mHomeProductItemCallback == null) {
            mHomeProductItemCallback = new DiffUtil.ItemCallback<ProductInfoApi.ThoroughBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull ProductInfoApi.ThoroughBean oldItem, @NonNull ProductInfoApi.ThoroughBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull ProductInfoApi.ThoroughBean oldItem, @NonNull ProductInfoApi.ThoroughBean newItem) {
                    return oldItem.getBeastly().equals(newItem.getBeastly());
                }
            };
        }
        return mHomeProductItemCallback;
    }

    public DiffUtil.ItemCallback<AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean> getLoanItemCallback() {
        if (mLoanItemCallback == null) {
            mLoanItemCallback = new DiffUtil.ItemCallback<AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean oldItem, @NonNull AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean oldItem, @NonNull AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean newItem) {
                    return oldItem.getBeastly().equals(newItem.getBeastly());
                }
            };
        }
        return mLoanItemCallback;
    }

    public DiffUtil.ItemCallback<File> getImageItemCallback() {
        if (mImageItemCallback == null) {
            mImageItemCallback = new DiffUtil.ItemCallback<File>() {
                @Override
                public boolean areItemsTheSame(@NonNull File oldItem, @NonNull File newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull File oldItem, @NonNull File newItem) {
                    return oldItem.getAbsolutePath().equals(newItem.getAbsolutePath());
                }
            };
        }
        return mImageItemCallback;
    }

    public DiffUtil.ItemCallback<GetBankInfoApi.HesitancyBean> getBankItemCallback() {
        if (mBankItemCallback == null) {
            mBankItemCallback = new DiffUtil.ItemCallback<GetBankInfoApi.HesitancyBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull GetBankInfoApi.HesitancyBean oldItem, @NonNull GetBankInfoApi.HesitancyBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull GetBankInfoApi.HesitancyBean oldItem, @NonNull GetBankInfoApi.HesitancyBean newItem) {
                    return oldItem.getBeastly().equals(newItem.getBeastly());
                }
            };
        }
        return mBankItemCallback;
    }

    public DiffUtil.ItemCallback<RepaymentMethodApi.MethodsBean> getRepaymentTypeItemCallback() {
        if (mRepaymentItemCallback == null) {
            mRepaymentItemCallback = new DiffUtil.ItemCallback<RepaymentMethodApi.MethodsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull RepaymentMethodApi.MethodsBean oldItem, @NonNull RepaymentMethodApi.MethodsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull RepaymentMethodApi.MethodsBean oldItem, @NonNull RepaymentMethodApi.MethodsBean newItem) {
                    return oldItem.getBuckthorn().equals(newItem.getBuckthorn());
                }
            };
        }
        return mRepaymentItemCallback;
    }
}
